/**
 * 国付宝网关B2C直连通道支付限额表
 */
var banks = {
	ICBC:{
		name:"中国工商银行",
		cards:{
			"借记卡/信用卡":[
				["500","1000","电子银行口令卡(无需开通短信认证)" ],
				["2000","5000","电子银行口令卡，开通短信认证" ],
				["5万","5万","静态密码器" ],
				["100万","100万","U盾（一代、二代）" ]
			]
		},
		comment:"存量静态密码用户的总累计限额为300元",
		tel:"95588"
	},
	CCB:{
		name:"中国建设银行",
		cards:{
			"借记卡":[
				["5000","5000","动态口令卡" ],
				["5000","5000","短信验证码" ],
				["5000","5000","文件证书+动态口令卡" ],
				["50万","50万","二代网银盾" ],
				["50万","50万","UKEY+动态口令卡" ]
			]
		},
		comment:"无",
		tel:"95533"
	},
	ABC:{
		name:"中国农业银行",
		cards:{
			"借记卡":[
				["1000","1000","K码支付(快捷）" ],
				["1000","3000","IE证书 （口令卡）" ],
				["10万","50万","K令支付" ],
				["50万","100万","一代K宝" ],
				["100万","500万","二代K宝" ]
			]
		},
		comment:"无",
		tel:"95599"
	},
	CMBC:{
		name:"民生银行",
		cards:{
			"借记卡":[
				["5000","5000","短信验证码" ],
				["5000","5000","浏览器证书" ],
				["50万","50万","动态令牌" ],
				["50万","50万","U宝" ]
			]
		},
		comment:"无",
		tel:"95568"
	},
	HXBC:{
		name:"华夏银行",
		cards:{
			"借记卡":[
				["300","300","直接支付" ],
				["5万","10万","电子钱包签约" ]
			]
		},
		comment:"无",
		tel:"95577"
	},
	PAB:{
		name:"平安银行",
		cards:{
			"借记卡":[
				["5万","5万","动态口令" ],
				["5万","5万","网银盾" ]
			],
			"信用卡":[
				["4000","4000","开通网上支付功能" ]
			]
		},
		comment:"无",
		tel:"95511 信用卡：4006695501"
	},
	BOBJ:{
		name:"北京银行",
		cards:{
			"借记卡":[
				["1000","5000","开通动态密码版网上支付功能" ],
				["100万","100万","开通证书版网上支付功能" ]
			]
		},
		comment:"如果您是普通版用户，可直接登录，总累计限额为300元。",
		tel:"96169"
	},
	BOC:{
		name:"中国银行",
		cards:{
			"借记卡":[
				["1000","5000","网银快付" ],
				["5万","借贷共用350万","专业版" ]
			],
			"信用卡":[
				["5000","借贷共用350万","专业版" ],
				["1000","5000","网银快付" ]
			]
		},
		comment:"无",
		tel:"95566"
	},
	CITIC:{
		name:"中信银行",
		cards:{
			"借记卡":[
				["1000","5000","办理动态口令" ],
				["1000","5000","办理移动证书" ],
				["1万","5万","口令+证书" ],
				["100万","100万","Ukey" ]
			]
		},
		comment:"无",
		tel:"95558"
	},
	CEB:{
		name:"光大银行",
		cards:{
			"借记卡":[
				["无","2万","网银专业版支付手机动态密码" ],
				["无","100万","网银专业版支付令牌动态密码" ],
				["无","50万","网银专业版支付阳光网盾" ]
			],
			"信用卡":[
				["300","300","手机密码" ],
				["300","300","令牌密码" ],
				["300","300","网盾证书" ]
			]
		},
		comment:"无",
		tel:"95595"
	},
	GDB:{
		name:"广发银行",
		cards:{
			"借记卡":[
				["500或3000","500或3000","手机动态验证" ],
				["500或2万","500或2万","Key盾" ]
			]
		},
		comment:"无",
		tel:"95508"
	},
	CIB:{
		name:"兴业银行",
		cards:{
			"借记卡":[
				["自选5000或5万","自选5000或5万","手机短信验证" ],
				["无限额","无限额","U盾证书" ]
			]
		},
		comment:"无",
		tel:"95561"
	},
	SPDB:{
		name:"上海浦东发展银行",
		cards:{
			"东方借记卡/东方准贷/活期一本通存折":[
				["无限额","无限额","数字证书用户" ],
				["20万元","20万元","动态密码用户" ]
			]
		},
		comment:"无",
		tel:"95528"
	},
	PSBC:{
		name:"中国邮政储蓄银行",
		cards:{
			"活期结算存折/借记卡":[
				["5万","5万","个人网银短信客户" ],
				["500万","500万","个人网银UK+短信金卡客户" ],
				["1000万","1000万","个人网银UK+短信白金卡、钻石卡客户" ]
			]
		},
		comment:"无",
		tel:"95580"
	},
	BOCOM:{
		name:"交通银行",
		cards:{
			"借记卡":[
				["5万","5万","手机注册用户" ],
				["5万","100万","证书认证用户" ]
			],
			"信用卡":[
				["1000元","1000元","手机注册用户" ],
				["1000元","1000元","证书认证用户" ]
			]
		},
		comment:"无",
		tel:"95559"
	},
	BOS:{
		name:"上海银行",
		cards:{
			"借记卡":[
				["3000","3000","动态口令" ],
				["50万","100万","E盾" ]
			],
			"信用卡":[
				["3000","6000","动态口令" ],
				["5万","信用卡透支额度","E盾" ]
			]
		},
		comment:"无",
		tel:"021-962888/95594"
	},
	NBCB:{
		name:"宁波银行",
		cards:{
			"借记卡":[
				["300","300","快速通道版（查询密码+电子支付密码）" ],
				["5万","5万","专业版（查询密码+手机动态密码）" ],
				["无限额","无限额","专业版（查询密码+USBKEY）" ]
			]
		},
		comment:"无",
		tel:"96528/962528"
	},
	CMB:{
		name:"招商银行",
		cards:{
			"一卡通":[
				["5000","5000","大众版" ],
				["无限额","无限额","专业版" ]
			],
			"信用卡":[
				["500","500","大众版" ],
				["500","500","专业版" ]
			]
		},
		comment:"无",
		tel:"95555"
	},
	TCCB:{
		name:"天津银行",
		cards:{
			"借记卡":[
				["无限额","无限额","证书版" ]
			]
		},
		comment:"无",
		tel:"4006-960296"
	},
	NJCB:{
		name:"南京银行",
		cards:{
			"借记卡":[
				["5万","5万","短信版" ]
			]
		},
		comment:"无",
		tel:"40088-96400"
	}
	
}


function payLimitTable(bankCode, isDialog){
	var bank = banks[bankCode];
	if(!bank){
		return '<tr class="pay_limit"></tr>';
	}
	var bankName = bank.name;
	var tel = nullToEmpty(bank.tel);
	var comment = nullToEmpty(bank.comment);
	
	var divMargin = "margin: 15px 6px 0px 0px;";
	if(isDialog){
		divMargin = "margin: 15px 6px 30px 0px;";
	}
	var limit = '<tr class="pay_limit" code="'+bankCode+'">' ;
		if(!isDialog){
			limit += '<th></th>';
		}
		limit += '<td colspan="4">'
	            + '<div class="box-xe" style="width:762px; overflow:hidden; color:#333333">'
	                + '<div class="xe-tips font12" style="margin-top: 15px;"><span class="b-box">'+ bankName +'</span>由于各银行限额随时调整，具体请咨询该行客服热线<em class="telWrap">'+ tel +'</em></div>'
	                + '<div class="tabel-xe hui333 mt15" style="' + divMargin + '">'  
	                + '<table class="" cellpadding="0" cellspacing="0" width="100%" style="table-layout: fixed;">'
	                   + '<tr>';
						if(isDialog){
							limit += '<th class="tc" style="width:15%;">银行卡种类</th>'
	                        + '<th class="tc" style="width:35%;">需要满足的条件</th>'
	                        + '<th class="tc" style="width:16%;">单笔限额(元)</th>'
	                        + '<th class="tc" style="width:16%;">每日限额(元)</th>'
	                        + '<th class="tc" style="width:18%;">备注</th>';
						}else{
							limit += '<th class="item" style="width:15%;">银行卡种类</th>'
	                        + '<th class="item" style="width:35%;">需要满足的条件</th>'
	                        + '<th class="item" style="width:16%;">单笔限额(元)</th>'
	                        + '<th class="item" style="width:16%;">每日限额(元)</th>'
	                        + '<th class="item" style="width:18%;">备注</th>';
						}
						limit += '</tr>';
	                    var flag = 1;//备注标记
	                    for(var i in bank.cards){
	                    	var card = bank.cards[i];
	                    	var num = 1;//tr跨行标记
	                    	for(var j in card){
	                    		var arr = card[j];
	                            limit += '<tr>';
	                            	if(num == 1){
	                            		limit += '<td rowspan="' + card.length +'" class="tc">'+ i +'</td>';
	                                }
	                                limit += '<td class="tc">'+ arr[2] +'</td>'
	                            		+ '<td class="tc">'+ arr[0] +'</td>'
	                                	+ '<td class="tc">' + arr[1] + '</td>';     
	                                if(flag == 1){                              
	                                	limit += '<td rowspan="100"  class="last" style="text-align: center;">'+ comment +'</td>';
	                            	}
	                            limit += '</tr>';
	                            num++;
	                            flag++;
	                    	}
						}
	
	                limit += '</table></div>'
	            + '</div>'
	        + '</td>'
	    + '</tr>';
	                
    return limit;
}

function nullToEmpty(str){
	return !str ? "" : str;
}

var showPayLimit = function(ele, scope){
	$(".ui-dialog-titlebar-close").addClass("ui-state-focus");
	if(!ele){
		if(!scope){
			ele = $("input[type=radio][name!='payChannel'][checked='checked']");
		}else{
			ele = $(scope).find("input[type=radio][name!='payChannel'][checked='checked']");
		}
	}
	if(ele){
		$(".pay_limit").remove();
		if($(ele).closest("div[class='bank-list ']").attr("id") != "personalBankList" 
			&& $(ele).closest("table").attr("id") != "personalBankList" 
			&& $(ele).closest("div").attr("id") != "allPersonBanksDialog"
			&& $(ele).closest(".personDialog").attr("id") != "allPersonBanksDialog"){//非个人返回
			return;
		}
		if($(ele).attr("name") == "creditPayBankCode"){
			return ;		//快捷支付返回
		}
		var isDialog = $(ele).closest("table").attr("id") != "personalBankList" 
					&& $(ele).closest("div[class='bank-list ']").attr("id") != "personalBankList" ;
		
		
		if(!isDialog){
			$(ele).closest("tbody").append(payLimitTable($(ele).val(), isDialog));
			if($("#bankPayBtn2").size() == 1 && $("#bankLoginBtnDiv").html() != ""){
				var btn = $("#bankLoginBtnDiv").html();
				$("#bankLoginBtnDiv").html("");
				$("#bankPayTab").find(".pay_limit").before("<tr><th></th><td>" + btn + "</td></tr>");
				$("#bankPayBtn2").removeClass("marginLeft141").addClass("marginTop20");
			}
		}else{
			var dialog = $(ele).closest(".personDialog");
			if(!dialog || dialog.size() < 1){
				
				$(ele).closest("table").next("table").find("tbody").append(payLimitTable($(ele).val(), isDialog));
				
			}else{
				var html = payLimitTable($(ele).val(),isDialog);
				$("#allPersonBanksDialog").append("<div class='pay_limit' style='padding-left:50px'>"+html+"</div>");
			}
		}
	}
	if($("#allPersonBanksDialog").find("tr[class='pay_limit']").size() > 0){//scope == ".ui-dialog"
		$(".box-xe").css("margin-left","44px");
		$("#allPersonBankPayForm").find("table[class='table-tml-3']:first").css("width","830px");
	}
}

$(function(){
	//脚本兼容支付页
	if($("div[id='personalBankList']").size() != 0){
		$("input[type='radio'][name='personalPayBankCode']:first").attr("checked","checked");
		
		$("input[type='radio'][name='personalPayBankCode']").click(function(){
			$("input[name='personalPayBankCode']").removeAttr("checked");
			$(this).attr("checked","checked");
			$(this).prop("checked",true);
		});
	}
	
	$("#personalBank").click(function(){
		$("input[type='radio'][name='personalPayBankCode']:first").attr("checked","checked");
	});
	
	$("#bankChannelSel").click(function(){//网银支付页签
		if($("#corpBank").prop("checked")){
			$(".pay_limit").remove();
			return;
		}
		$("input[name='personalPayBankCode']").attr("checked","");
		$("input[name='personalPayBankCode']:first").attr("checked","checked");
		showPayLimit();
	});
	
	$("#expressChannelSel").click(function(){//快捷支付页签
		$(".pay_limit").remove();
//		$("#bankPayBtn2").remove();
		$("#creditBankList").css("padding-left","30px");
		$("#debitBankList").css("padding-left","30px");
	});
	
	//脚本兼容支付页结束
	
	$("input[type='radio']").click(function(){
		var bankCode = null;
		var ele = null;	//被点击的radio
		
		if($(this).attr("id") == "corpBank"){//企业银行
			$(".pay_limit").remove();
		}
		if($(this).attr("name") == "payChannel"){
			ele = $("input[type=radio][name='personalPayBankCode'][checked='checked']");
		}
		else if($(this).attr("name") == "bankPayChannel"){
			ele = $("input[type=radio][name='personalPayBankCode'][checked='checked']");
		}
		else{
			ele = this;
		}
		if($(ele).attr("name") != "personalPayBankCode" 
			&& $(ele).attr("name") != "payChannel" 
			&& $(ele).attr("name") != "personalPayBankCodeAll" 
			&& $(ele).attr("name") != "bankPayChannel"){
			return ;
		}
		if($(".pay_limit").attr("code") == $(ele).val()){
			return ; //防止两次触发
		}
		showPayLimit(ele);
	});
	
	$("#personalBankList,#allPersonBanksDialog").find("img").click(function(){
		$(this).closest("td").find("input[type='radio']").trigger("click");
	});
	
	if(!$("#corpBank").prop("checked")){
		showPayLimit();
	}
});

